package org.dce.screencapturer.objects;

import java.awt.Color;
import java.awt.Font;
import java.awt.font.TextAttribute;
import java.util.HashMap;
import java.util.Map;

import org.dce.screencapturer.util.ObjectUtils;

public class TextAttributes {

	public enum VerticalAlignment {
		TOP,
		MIDDLE,
		BOTTOM
	}
	
	public enum HorizontalAlignment {
		LEFT,
		CENTER,
		RIGHT
	}
	
	private Color color = Color.BLACK;
	private Font font;
	private VerticalAlignment verticalAlignment = VerticalAlignment.MIDDLE;
	private HorizontalAlignment horizontalAlignment = HorizontalAlignment.CENTER;
	
	public TextAttributes(){
		
		Map<TextAttribute,Object> attributes = new HashMap<TextAttribute, Object>();
		attributes.put(TextAttribute.FAMILY, Font.SERIF);
		attributes.put(TextAttribute.SIZE, 18);
		attributes.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_REGULAR);
		attributes.put(TextAttribute.POSTURE, TextAttribute.POSTURE_REGULAR);
		font = new Font(attributes);
	}
	
	public TextAttributes(
			Font font, 
			VerticalAlignment verticalAlignment,
			HorizontalAlignment horizontalAlignment,
			Color color) {
		this.font = font;
		this.verticalAlignment = verticalAlignment;
		this.horizontalAlignment = horizontalAlignment;
		this.color = color;
	}
	public Font getFont() {
		return font;
	}
	public void setFont(Font font) {
		this.font = font;
	}
	public VerticalAlignment getVerticalAlignment() {
		return verticalAlignment;
	}
	public void setVerticalAlignment(VerticalAlignment verticalAlignment) {
		this.verticalAlignment = verticalAlignment;
	}
	public HorizontalAlignment getHorizontalAlignment() {
		return horizontalAlignment;
	}
	public void setHorizontalAlignment(HorizontalAlignment horizontalAlignment) {
		this.horizontalAlignment = horizontalAlignment;
	}
	public Color getColor() {
		return color;
	}
	public void setColor(Color color) {
		this.color = color;
	}
	
	public int hashCode(){
		
		return 
			new StringBuilder()
			.append(font)
			.append("-").append(verticalAlignment)
			.append("-").append(horizontalAlignment)
			.append("-").append(color)
			.toString()
			.hashCode();
	}

	public Object clone(){
		return new TextAttributes(font, verticalAlignment, horizontalAlignment,color);
	}
	
	public boolean equals(Object other){
		return other instanceof TextAttributes
			&& ObjectUtils.equals(font,((TextAttributes)other).font)
			&& horizontalAlignment.equals(((TextAttributes)other).horizontalAlignment)
			&& verticalAlignment.equals(((TextAttributes)other).verticalAlignment)
			&& ObjectUtils.equals(color,((TextAttributes)other).color);
	}
}
